package org.rich.charlesmurphy.ui.renderers;

import java.awt.Color;
import java.awt.Component;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import org.ddevil.data.Data;
import org.rich.charlesmurphy.core.CMIds;
import org.rich.charlesmurphy.core.CharliesUtils;
import org.rich.charlesmurphy.model.ResourceType;
import org.rich.charlesmurphy.ui.Colors;
import org.windowkit.toolkit.widget.table.RecordTableModel;
import org.windowkit.toolkit.widget.table.render.AbstractBackgroundRenderer;

/**
 * Renders bg color based on file type.
 * @author Rich
 */
public class FileTypeColorRenderer extends AbstractBackgroundRenderer {

	private static Map<ResourceType, Color> colorMap;
	static {
		colorMap = new HashMap<ResourceType, Color>(ResourceType.values().length);
		colorMap.put(ResourceType.AJAX, Colors.AJAX);
		colorMap.put(ResourceType.CSS, Colors.CSS);
		colorMap.put(ResourceType.JS, Colors.JS);
		colorMap.put(ResourceType.IMAGE, Colors.IMAGE);
		colorMap.put(ResourceType.PAGE, Colors.SUCCSSS);
		colorMap.put(ResourceType.OTHER, Colors.OTHER);
	}


	public FileTypeColorRenderer() {
		super();
	}

	FileTypeColorRenderer(TableCellRenderer decorateMe) {
		super(decorateMe);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected Color getColor(Component c, Data d, RecordTableModel model,
			JTable table, Object value, CellInfo info) {

		ResourceType type = CharliesUtils.determineResourceType((String)d.getValue(CMIds.PATH));
		return colorMap.get(type);
	}
}
